import configparser

class ConfigUtils:
    def __init__(self,config_file_path):
        self.cfg_path = config_file_path
        self.cfg =configparser.ConfigParser()
        self.cfg.read(self.cfg_path,encoding='utf-8')

    def read_value(self,section,key):
        if self.cfg.has_option(section,key):
            value = self.cfg.get(section,key)
        else:
            value = ""
        return value

    def get_sections(self):
        return self.cfg.sections()

    def is_exist_section(self,section):
        if section in self.cfg.sections():
            return True
        else:
            return False

    def write_value(self,section,key,value):
        if self.cfg.has_section(section) == False:
            self.cfg.add_section(section)
        self.cfg.set(section,key,value)
        config_file_obj = open(self.cfg_path, "w",encoding='utf-8')
        self.cfg.write(config_file_obj)
        config_file_obj.flush()
        config_file_obj.close()